﻿Type.registerNamespace("RFBR.BaseComponent");
RFBR.BaseComponent = function (settings) {
    if (!this._events) {
        this._events = [];
    }
    this._events = this._events.concat(["SizeChanged"]);
    this._MinWidth = 1024;
    this._MinHeight = 600;
    this._AppPath;
    this._PortalContainer = null
    settings.Inited = { func: this._init, context: this };

    RFBR.BaseComponent.initializeBase(this, arguments);

    this._attachEvents();

    var resizeHandler = function () {
        this._resizePortalContainer();
        this.SizeChanged.fire(this);
    }.bind(this);
    window.onresize = function () {
        var timeoutId = window.setTimeout(function () {
            window.clearTimeout(timeoutId);
            resizeHandler();
        }.bind(this), 10);
    }
}

var baseProto = RFBR.BaseComponent.prototype;

baseProto._init = function () {

};

baseProto._resizePortalContainer = function () {
    var winH = document.compatMode == 'CSS1Compat' && !window.opera ? document.documentElement.clientHeight : document.body.clientHeight;
    winH -= $('header').outerHeight(true);
    var minH = this._MinHeight - $('header').outerHeight(true);
    if (winH > minH) {
        $(this._PortalContainer).height(winH);
        document.body.style.overflowY = "hidden";
    }
    else {
        $(this._PortalContainer).height(minH);
        document.body.style.overflowY = "auto";
    }

    var winW = document.compatMode == 'CSS1Compat' && !window.opera ? document.documentElement.clientWidth : document.body.clientWidth;
    var minW = this._MinWidth;
    if (winW > minW) {
        $('header').width(winW);
        $(this._PortalContainer).width(winW);
        document.body.style.overflowX = "hidden";
    }
    else {
        $('header').width(minW);
        $(this._PortalContainer).width(minW);
        document.body.style.overflowX = "auto";
    }
};

baseProto._attachEvents = function () {
    var self = this;
};

baseProto = null;

RFBR.BaseComponent.registerClass("RFBR.BaseComponent", RFBR.Object);